import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios';

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
      list:[]
        
  },
  mutations: {
      setList(state,list){
        state.list = list
      },
      addTask(state,{txt,index}){
        let children = state.list[index].children;
        children.push({
            id:children.length+1,
            name:txt
        })
        console.log(state.list)
      },
      //删除
      delTask(state,{index,ind}){
        state.list[index].children.splice(ind,1)
      },
      //新建
      newAdd(state,txt){
        state.list.push({
            id:state.list.length+1,
            name:txt,
            children:[]
        })
      }
  },
  actions: {
      getList({commit}){
        axios.get('/api/list').then(res => {
            commit('setList',res.data.data);
        })
      }
  },
  modules: {
  }
})
